package com.hsp_java.list_;

public class LinkedList01 {
    public static void main(String[] args) {
        Node tom = new Node("Tom");
        Node john = new Node("John");
        Node jack = new Node("Jack");
        Node lfm = new Node("lfm");

        tom.nxt = john;
        john.pre = tom;
        john.nxt = jack;
        jack.pre = john;

        john.nxt = lfm;
        lfm.pre = john;
        lfm.nxt = jack;
        jack.pre = lfm;

        Node first = tom;
        Node last = jack;

        while (first != null) {
            System.out.println(first);
            first = first.nxt;
        }

        while (last != null) {
            System.out.println(last);
            last = last.pre;
        }

    }
}


class Node {

    Object name;
    Node pre;
    Node nxt;

    public Node(Object name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Node{" +
                "name=" + name +
                '}';
    }
}